using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using GeneralLibs;
using BasicForms;
using System.Collections;
using Lists;

namespace KhuyenMai
{
    public partial class FrmDanhSachChuongTrinhKhuyenMaiTheoThoiGian : FrmDanhSachChuongTrinhKhuyenMai
    {
        public FrmDanhSachChuongTrinhKhuyenMaiTheoThoiGian()
        {
            InitializeComponent();
            _KieuKhuyenMai = KieuKhuyenMai.TheoThoiGian;
            colNgayBatDauTinhTongTien.Visible = false;
            colNgayKetThucTinhTongTien.Visible = false;
        }

        void frm_RequestAddNew()
        {
            try
            {
                FrmEditKhuyenMaiTheoThoiGian frm = new FrmEditKhuyenMaiTheoThoiGian(Guid.Empty);
                frm.RequestAddNew += new FrmEditKhuyenMaiTheoThoiGian.OnRequestAddNew(frm_RequestAddNew);
                frm.Show();
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }

        public override void CreateNew()
        {
            try
            {
                FrmEditKhuyenMaiTheoThoiGian frm = new FrmEditKhuyenMaiTheoThoiGian(Guid.Empty);
                frm.RequestAddNew += new FrmEditKhuyenMaiTheoThoiGian.OnRequestAddNew(frm_RequestAddNew);
                frm.Show();
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }

        protected override void Edit()
        {
            try
            {
                ArrayList arDeletedChuongTrinhKhuyenMai = new ArrayList();
                foreach (int index in gridViewDsChuongTrinhKhuyenMai.GetSelectedRows())
                {
                    arDeletedChuongTrinhKhuyenMai.Add(_DanhSachChuongTrinhKhuyenMai.GetByDataRow(gridViewDsChuongTrinhKhuyenMai.GetDataRow(index)));
                }
                gridViewDsChuongTrinhKhuyenMai.BeginUpdate();
                foreach (ChuongTrinhKhuyenMai chuongTrinhKhuyenMai in arDeletedChuongTrinhKhuyenMai)
                {
                    FrmEditKhuyenMaiTheoThoiGian frm = new FrmEditKhuyenMaiTheoThoiGian(chuongTrinhKhuyenMai);
                    frm.RequestAddNew += new FrmEditKhuyenMaiTheoThoiGian.OnRequestAddNew(frm_RequestAddNew);
                    frm.Show();
                }
                gridViewDsChuongTrinhKhuyenMai.EndUpdate();
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
        }

        
    }
}